NumericUpDown = {
	new = function (scr, x, y, w, h, val, valMin, valMax, step)
		local x2 = x+w
		local y2 = y+h
		local tmr = Timer.new()
		
		local up = {
			x = x2,
			y = y,
			x2 = x2+math.floor(w/4),
			y2 = y+math.floor(h/2)
		}
		up.txtx = (up.x+(up.x2-up.x)/2)-4
		up.txty = (up.y+(up.y2-up.y)/2)-3
		
		local down = {
			x = x2,
			y = y2-math.floor(h/2),
			x2 = x2+math.floor(w/4),
			y2 = y2
		}
		down.txtx = (down.x+(down.x2-down.x)/2)-4
		down.txty = (down.y+(down.y2-down.y)/2)-3
		
		local isChanging = false
		
		local draw = function ()
			txt = tostring (val)
			txtx = (x2-(string.len(txt)*6))-3
			txty = (y+h/2)-3
			
			screen.drawRect (scr, x-1, y-1, x2+1, y2+1, c_black)
			screen.drawFillRect (scr, x+1, y, x2-1, y2, c_white)
			screen.drawFillRect (scr, up.x, up.y, up.x2, up.y2, c_grey)
			screen.drawFillRect (scr, down.x, down.y, down.x2, down.y2, c_grey)
			screen.print (scr, txtx, txty, txt, c_black)
			screen.print (scr, up.txtx, up.txty, "+", c_black)
			screen.print (scr, down.txtx, down.txty, "-", c_black)
			
			if StylusBox.simpleHold(up.x, up.y, up.x2, up.y2, Stylus.X, Stylus.Y) then
				tmr:start()
				if tmr:time() == 0 and not isChanging then
					val = val+step
				elseif tmr:time() >= 1000 then
					val = val+step
					isChanging = true
					tmr:reset()
				end
			elseif StylusBox.simpleHold(down.x, down.y, down.x2, down.y2, Stylus.X, Stylus.Y) then
				tmr:start()
				if tmr:time() == 0 and not isChanging then
					val = val-step
				elseif tmr:time() >= 1000 then
					val = val-step
					isChanging = true
					tmr:reset()
				end
			end
			
			if Stylus.released then
				tmr:stop()
				tmr:reset()
				isChanging = false
			end
			
			if val >= valMax then
				val = valMax
			elseif val <= valMin then
				val = valMin
			end
		end
		
		local getValue = function ()
			return val
		end
		
		local getMaxValue = function ()
			return valMax
		end
		
		local getMinValue = function ()
			return valMin
		end
		
		local getStep = function ()
			return step
		end
		
		local clear = function ()
			self = nil
		end
		
		return {
			draw = draw,
			getValue = getValue,
			getMaxValue = getMaxValue,
			getMinValue = getMinValue,
			getStep = getStep,
			clear = clear
		}
	end
}
